<template>
	<el-container v-loading="loading">
		<el-container>
			<el-header>
				<div class="right-panel-search">
					<el-input v-model="search.patient_sn" placeholder="订单编号" clearable
							  style="min-width:15%;"></el-input>
					<el-input v-model="search.user_mobile" placeholder="用户账号" clearable
							  style="min-width:15%;"></el-input>
					<el-input v-model="search.username" placeholder="用户名称" clearable
							  style="min-width:15%;"></el-input>
				</div>
			</el-header>
			<el-header>
				<div class="right-panel-search">
					<el-input v-model="search.user_company" placeholder="单位名称" clearable
							  style="min-width:15%;width:200px;"></el-input>
					<el-select v-model="search.order_status" placeholder="订单状态" style="min-width:15%;" clearable>
						<el-option v-for="item in statusList" :key="item.status" :label="item.status_name"
								   :value="item.status">
						</el-option>
					</el-select>
					<el-date-picker
						style="min-width:25%;"
						v-model="dateTo"
						type="datetimerange"
						unlink-panels
						range-separator="至"
						start-placeholder="创建时间"
						end-placeholder="结束时间"
						format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss"
						clearable="true"
					/>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
					<el-button type="info" @click="resetsearch">重置</el-button>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable ref="table" :apiObj="apiObj" @selection-change="selectionChange" :params="search" stripe
						 remoteSort
						 remoteFilter>
					<el-table-column label="订单编号" prop="patient_sn" width="200"></el-table-column>
					<el-table-column label="用户账号" prop="user_mobile" width="150"></el-table-column>
					<el-table-column label="用户名称" prop="username" width="150"></el-table-column>
					<el-table-column label="单位名称" prop="user_company" width="150"></el-table-column>
					<el-table-column label="商品名称" prop="product_name" width="150"></el-table-column>
					<el-table-column label="就诊人" prop="patient_name" width="150"></el-table-column>
					<el-table-column label="等待期" prop="wait_day" width="150"></el-table-column>
					<el-table-column label="服务商" prop="provider_name" width="150"></el-table-column>
					<el-table-column label="激活时间" prop="service_open_at" width="150"></el-table-column>
					<el-table-column label="下单时间" prop="created_at"
									 width="150"></el-table-column>
					<el-table-column label="操作" fixed="right" align="right" width="160">
						<template #default="scope">
							<el-button-group>
								<el-button text type="primary" size="small" @click="table_show(scope.row)"
										   v-auth="'patient_green:order:info'">查看
								</el-button>
							</el-button-group>
						</template>
					</el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-dialog>
</template>

<script>
import saveDialog from './patient_order_detail.vue'

export default {
	name: 'order',
	components: {
		saveDialog
	},
	data() {
		return {
			dialog: {
				save: false
			},
			showGroupLoading: false,
			loading: false,
			apiObj: this.$API['patient.jing_yi_yun'].orderList,
			selection: [],
			statusList: [
				{status: 0, status_name: "全部"},
				{status: 10, status_name: "进行中"},
				{status: 20, status_name: "已完成"},
				{status: 30, status_name: "订单取消"},
				{status: 40, status_name: "未处理"},
			],
			//时间搜索
			dateTo: [],
			search: {
				patient_sn: null,
				user_mobile: null,
				username: null,
				user_company: null,
				order_status: null,
				created_at_begin: null,
				created_at_end: null,
			},
		}
	},
	watch: {
		dateTo(val) {
			if (val) {
				this.search.created_at_begin = val[0];
				this.search.created_at_end = val[1];
			} else {
				this.search.created_at_begin = '';
				this.search.created_at_end = '';
			}
		},
	},
	mounted() {
	},
	methods: {
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		//重置
		resetsearch() {
			this.dateTo = [];
			this.search = {
				patient_sn: null,
				user_mobile: null,
				username: null,
				user_company: null,
				order_status: null,
				created_at_begin: null,
				created_at_end: null,
			}
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess() {
			this.dialog.save = false
			this.$refs.table.reload()
		},
		//查看
		table_show(row) {
			this.$router.push({
				path: '/patient/patient_green_order_detail',
				query: {
					patient_sn: row.patient_sn,
					action: 'view'
				}
			})
		},
	}
}
</script>
